package com.situ.day2;

import java.util.Scanner;

import org.junit.Test;

public class WhileDemo {

	@Test
	public void test1() {
		// 1、循环条件的初始化
		int i = 1;
		// 2、循环条件的控制
		while (i <= 5) {
			System.out.println("HelloWorld!");
			// 3、循环条件的改变（趋向于循环条件的结束）
			i++;
		}
	}
	
	// 1+2+3+4+...+100
	@Test
	public void test2() {
		int i = 1;
		int sum = 0;
		while (i <= 100) {
			System.out.println(i);
			sum = sum + i;// sum += i;
			// sum = sum * 0.8;// sum *= 0.8;
			i++;
		}
		System.out.println("sum: " + sum);
	}
	
	// 1*9=9  2*9=18  3*9=27 ...  8*9=72  9*9=81
	@Test
	public void test7() {
		int i = 1;
		while (i <= 9) {
			System.out.print(i + "*9=" + (i * 9) + "\t");
			i++;
		}
	}
	
	@Test
	public void test55() {
		// >= 0.0   <1.0
		//double greater than or equal to 0.0 and less than 1.0.
		//             0.0--------------0.999999999...
		// *1000       0.0--------------999.9999999...
		// +1          1.0--------------1000.999999...
		// (int)       1----------------1000
		int random = (int)(Math.random() * 1000 + 1);
		System.out.println(random);
		Scanner scanner = new Scanner(System.in);
		while (true) {
			System.out.println("猜吧");
			int num = scanner.nextInt();
			if (num > random) {
				System.out.println("太大了");
			} else if (num < random) {
				System.out.println("太小了");
			} else {
				System.out.println("猜对了");
				break;//调出当前循环，只能跳出一层循环
			}
		}
		System.out.println("end");
		
	}
	
	@Test
	public void test444() {
		Scanner scanner = new Scanner(System.in);
		int password = 0;
		do {
			System.out.println("请输入密码：");
			password = scanner.nextInt();
		} while(password != 123);
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
}
